import Popup from './index.vue'
 
export default {
  install(Vue) {
    const Profile = Vue.extend(Popup)
 
    // 弹出弹窗
    Vue.prototype.$openPopUp = function(params) {
      const instance = new Profile()
      for (const key in params) {
        if (Object.hasOwnProperty.call(params, key)) {
          const value = params[key]
          instance[key] = value
        }
      }
      instance.vm = instance.$mount()
      const popUpEle = document.body.lastElementChild
      if (popUpEle.className === 'global-alert') return
      setTimeout(() => document.body.appendChild(instance.vm.$el))
      return instance
    }
 
    // 关闭弹窗
    Vue.prototype.$closePopUp = function() {
      const instance = new Profile()
      instance.vm = instance.$mount()
      const popUpEle = document.body.lastElementChild
      if (popUpEle.className !== 'global-alert') return
      document.body.removeChild(popUpEle)
      return instance
    }
  }
}